#include <iostream>
#include <stdlib.h>
typedef struct List
{
	int sum;
	List *next;
}list,*Linked_List;

Linked_List List_input(int x) //输入
{
	list *temp, *R_variable, *head;
	R_variable=temp = new List;
	for (int i = 0; i < x; i++)
	{
		head = new List;
		std::cin >> head->sum;
		head->next = NULL;
		temp->next = head;
		temp = head;
	}
	return R_variable;
}

Linked_List List_Instet(list *point,int x,int data) //x为插入的位置 data为插入的数据
{
	list *head;
	int i = 0;
	while (i < x - 1 && point->next != NULL) //查找插入位置 如果没找到
	{
		i++;
		point = point->next; //直到找到了为止
	}

	if (i == x - 1) //如果找到了 插入
	{
		head = new List;
		head->sum = data;
		head->next = point->next;
		point->next = head;
	}
	else
	{
		std::cout << "没有这个位置";
		exit(1);
	}
	return head;
}

Linked_List List_delete(list *point, int x) //删除
{
	list *head;
	int i = 0;
	while (i < x - 1 && point->next != NULL) 
	{
		i++;
		point = point->next;
	}
	if (i == x - 1)
	{
		head = new List;
		head->sum = x;
		head = point->next;
		point->next = head->next;
		delete head;
	}
	return point;
}
Linked_List List_Output(list *point) //输出
{
	while (point->next != NULL)
	{
		point = point->next;
		std::cout << point->sum;

	}
	return point;
}
Linked_List lenght(list *point) //链表长度
{
	int i=0;
	while (point->next != NULL)
	{
		i++;
		point = point->next;
	}
	std::cout <<std::endl<<i;
	return point;
}

Linked_List Initialization_List(list *point) //初始化链表
{
	point->next = NULL;
	point->sum = 0;
	return point;
}
int main()
{
	list *temp;
	int position,data,x;
	temp=List_input(4); //输入
	
	std::cout << "输入插入位置";
	std::cin >> position;
	std::cout<<"输入插入数据";
	std::cin >> data;
	List_Instet(temp, position, data); //插入
	List_Output(temp); //输出

	std::cout << std::endl << "输出删除的数";
	std::cin >> x;
	List_delete(temp, x); //删除
	List_Output(temp); //输出
}